<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WinRTXamlToolkit.Controls">
    <Style
        TargetType="local:Gauge">
        <Setter
            Property="Template">
            <Setter.Value>
                <ControlTemplate
                    TargetType="local:Gauge">
                    <Viewbox>
                        <Grid
                            Height="200"
                            Width="200">

                            <!-- Ticks -->
                            <Line
                                x:Name="TicksProxy"
                                Visibility="Collapsed"
                                Fill="{TemplateBinding TickBrush}" />
                            <ItemsControl
                                ItemsSource="{TemplateBinding Ticks}"
                                VerticalAlignment="Center"
                                HorizontalAlignment="Center">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <Canvas />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Rectangle
                                            Height="18"
                                            Width="5"
                                            Fill="{Binding Fill, ElementName=TicksProxy}">
                                            <Rectangle.RenderTransform>
                                                <TransformGroup>
                                                    <TranslateTransform
                                                        X="-2.5"
                                                        Y="-100" />
                                                    <RotateTransform
                                                        Angle="{Binding}" />
                                                </TransformGroup>
                                            </Rectangle.RenderTransform>
                                        </Rectangle>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>

                            <!-- Scale -->
                            <Path
                                Name="PART_Scale"
                                Stroke="{TemplateBinding ScaleBrush}"
                                StrokeThickness="{TemplateBinding ScaleWidth}" />

                            <!-- Trail -->
                            <Path
                                Name="PART_Trail"
                                Stroke="{TemplateBinding TrailBrush}"
                                StrokeThickness="{TemplateBinding ScaleWidth}" />

                            <!-- Scale Ticks -->
                            <Line
                                x:Name="ScaleTicksProxy"
                                Visibility="Collapsed"
                                Fill="{TemplateBinding ScaleTickBrush}"
                                X1="{TemplateBinding ScaleWidth}" />
                            <ItemsControl
                                ItemsSource="{TemplateBinding Ticks}"
                                VerticalAlignment="Center"
                                HorizontalAlignment="Center">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <Canvas />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Rectangle
                                            Height="{Binding X1, ElementName=ScaleTicksProxy}"
                                            Width="2"
                                            Fill="{Binding Fill, ElementName=ScaleTicksProxy}">
                                            <Rectangle.RenderTransform>
                                                <TransformGroup>
                                                    <TranslateTransform
                                                        X="-0.5"
                                                        Y="-77" />
                                                    <RotateTransform
                                                        Angle="{Binding}" />
                                                </TransformGroup>
                                            </Rectangle.RenderTransform>
                                        </Rectangle>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>

                            <!-- Value and Unit -->
                            <StackPanel
                                VerticalAlignment="Bottom"
                                HorizontalAlignment="Center">
                                <TextBlock
                                    Name="PART_ValueText"
                                    Foreground="{TemplateBinding ValueBrush}"
                                    FontSize="20"
                                    FontWeight="SemiBold"
                                    Text="{TemplateBinding Value}"
                                    TextAlignment="Center"
                                    Margin="0 0 0 2" />
                                <TextBlock
                                    Foreground="{TemplateBinding UnitBrush}"
                                    FontSize="16"
                                    TextAlignment="Center"
                                    Text="{TemplateBinding Unit}"
                                    Margin="0" />
                            </StackPanel>

                            <!-- Needle -->
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition
                                        Height="*" />
                                    <RowDefinition
                                        Height="*" />
                                </Grid.RowDefinitions>

                                <!-- The RenderTransform is in code behind. -->
                                <Path
                                    Name="PART_Needle"
                                    Stretch="Uniform"
                                    HorizontalAlignment="Center"
                                    Fill="{TemplateBinding NeedleBrush}"
                                    Data="M 0,0 l 0,100 l 5,0 l 0,-100 l -5,0"
                                    RenderTransformOrigin="0.5,1">
                                </Path>
                            </Grid>
                        </Grid>
                    </Viewbox>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
